<template>
	<view class="clock-wrapper">
		<view class='card'>
			<view class='time-wrapper'>
				<image src="../static/tomato.png" class='photo'></image>
				<view class='time' @click="setTime(clock)">{{time}}</view>
			</view>
			<view class='content-wrapper'>
				<view class='content'>
					<view>鸟随鸾凤飞高远，</view>
					<view>人伴贤良品自高。</view>
				</view>
				<view class="iconfont" @click="$emit('update:show',false)">&#xe61f;</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "CountDown",
		data() {
			return {
				time: '开始',
				second: 60
			};
		},
		created() {
			this.$store.commit('getTomato')
		},
		computed: {
			tomato() {
				return this.$store.state.tomatoData.tomato
			},
		},
		props: ['clock'],
		methods: {
			setTime(clock) {
				this.time = clock
				this.second = this.time * 60
				const countDown = setInterval(() => {
					if (this.second === 0) {
						clearInterval(countDown)
					} else {
						this.second = this.second - 1
						let nowSecond = this.second
						this.time = Number(this.secondToMinute(nowSecond))
					}
				}, 1000)
			},
			secondToMinute(time) {
				let a = (time / 60).toString() // 整数位
				let b = (time % 60).toString() // 小数位
				if (a.length <= 2) {
					return a + '.' + b
				} else {
					let c = a.slice(0, 2)
					if (Number(a) < 1) {
						if (b.length === 1) {
							return '00.0' + b

						} else {
							return '00.' + b
						}
					}
					if (Number(a) < 10) {
						if (b.length === 1) {
							return '0' + c + '0' + b
						} else {
							return '0' + c + b
						}
					}
					if (b.length === 1) {
						return c + '.0' + b
					} else {
						return c + '.' + b
					}

				}
			},

		}
	}
</script>

<style lang="scss">
	.clock-wrapper {
		position: fixed;
		width: 100vw;
		height: 100vh;
		z-index: 100;
		background: rgba(98, 99, 100, 0.8);
		top: 0;
		right: 0;
		color: #f8f7f7;
		display: flex;
		justify-content: center;

		.card {
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			>.time-wrapper {
				display: flex;
				flex-direction: column;
				background: linear-gradient(214deg, rgba(139, 31, 134, 1) 0%, rgba(148, 168, 233, 1) 100%);
				border-top-left-radius: 20px;
				border-top-right-radius: 20px;
				width: 90vw;
				height: 50vh;

				.photo {
					margin: 20px;
					width: 30px;
					height: 30px;
					flex-shrink: 0;
				}

				.time {
					display: flex;
					justify-content: center;
					margin-top: 100px;
					font-size: 40px;
				}
			}

			>.content-wrapper {
				display: flex;
				background-color: #f3f3f3;
				color: black;
				width: 100%;
				border-bottom-left-radius: 20px;
				border-bottom-right-radius: 20px;
				height: 250px;
				justify-content: center;
				align-items: center;

				.content {
					font-size: 20px;
					margin-right: 20px;
					letter-spacing: 0.1em;
				}

				.iconfont {
					font-size: 60px;
				}
			}

		}

	}
</style>
